1 using System;
2 using
System.Collections.Generic;
3 using
System.ComponentModel;
4 using
System.Drawing;
5 using
System.Data;
6 using
System.Linq;
7 using
System.Text;
8 using
System.Threading.Tasks;
9 using
System.Windows.Forms;
10
11 namespace
SoftQuanLyNhaHang.Views
12 {
13     
public partial class uctLoaiThucDon : UserControl
14     {
15         
public uctLoaiThucDon()
16         {
17             InitializeComponent();
18         }
19         
public static uctLoaiThucDon uctLTD = new uctLoaiThucDon();
20         
int flag = 0;
21         
private void uctLoaiThucDon_Load(object sender, EventArgs e)
22         {
23             HienThiDanhSachLTD();
24             bingding();
25             dis_end(
false);
26         }
27         
public void HienThiDanhSachLTD()
28         {
29             dgvDanhSachLTD.DataSource = Models.LoaiThucDonMod.FillDataSetLoaiThucDon().Tables[
0];
30             dgvDanhSachLTD.RowHeadersVisible =
false;
31             dgvDanhSachLTD.BorderStyle = BorderStyle.Fixed3D;
32         }
33         
void bingding()
34         {
35             txtIdLTDon.DataBindings.Clear();
36             txtIdLTDon.DataBindings.Add(
"Text", dgvDanhSachLTD.DataSource, "IdLoaiThucDon");
37             txtTenLTDon.DataBindings.Clear();
38             txtTenLTDon.DataBindings.Add(
"Text", dgvDanhSachLTD.DataSource, "TenLoaiThucDon");
39             txtDienGiaiLTDon.DataBindings.Clear();
40             txtDienGiaiLTDon.DataBindings.Add(
"Text", dgvDanhSachLTD.DataSource, "DienGiai");
41             cmbTrangThaiLTDon.DataBindings.Clear();
42             cmbTrangThaiLTDon.DataBindings.Add(
"Text", dgvDanhSachLTD.DataSource, "TrangThai");
43
44         }
45         
void loadcontrol()
46         {
47             cmbTrangThaiLTDon.Items.Clear();
48             cmbTrangThaiLTDon.Items.Add(
"Còn hàng");
49             cmbTrangThaiLTDon.Items.Add(
"Đã hết");
50             cmbTrangThaiLTDon.Items.Add(
"Sắp hết");
51
52         }
53         
void clearData()
54         {
55             txtIdLTDon.Text = Models.connection.ExcuteScalar(String.Format(
"select IdLoaiThucDon= dbo.fcgetIdLoaiThucDon()"));
56             txtTenLTDon.Text =
"";
57             txtDienGiaiLTDon.Text =
"";
58             loadcontrol();
59         }
60         
void dis_end(bool e)
61         {
62             txtTenLTDon.Enabled = e;
63             txtDienGiaiLTDon.Enabled = e;
64             cmbTrangThaiLTDon.Enabled = e;
65             btnLuu.Enabled = e;
66             btnHuy.Enabled = e;
67             btnThemMoi.Enabled = !e;
68             btnXoa.Enabled = !e;
69             btnSua.Enabled = !e;
70         }
71
72         
private void btnThemMoi_Click(object sender, EventArgs e)
73         {
74
75             flag =
0;
76             clearData();
77             dis_end(
true);
78         }
79
80         
private void btnHuy_Click(object sender, EventArgs e)
81         {
82             uctLoaiThucDon_Load(sender, e);
83             dis_end(
false);
84         }
85
86         
private void btnLuu_Click(object sender, EventArgs e)
87         {
88             
string _idLTD = "";
89             
try
90             {
91                 _idLTD = txtIdLTDon.Text;
92             }
93             
catch { }
94             
string _tenLTD = "";
95             
try
96             {
97                 _tenLTD = txtTenLTDon.Text;
98             }
99             
catch { }
100             
string _dienGiai = "";
101             
try
102             {
103                 _dienGiai = txtDienGiaiLTDon.Text;
104             }
105             
catch { }
106             
string _trangThai = "";
107             
try
108             {
109                 _trangThai = cmbTrangThaiLTDon.Text;
110             }
111             
catch { }
112             
if (flag == 0)
113             {
114
115
116                 
if (_tenLTD == "")
117                     MessageBox.Show(
"Hãy nhập tên loại thực đơn");
118                 
else
119                 {
120                     
int i = 0;
121                     i = Controllers.LoaiThucDonCtrl.InsertLoaiThucDon(_idLTD,_tenLTD,_dienGiai,_trangThai);
122                     
if (i > 0)
123                     {
124                         MessageBox.Show(
"Thêm mới thành công");
125                         HienThiDanhSachLTD();
126                     }
127                     
else
128                         MessageBox.Show(
"Thêm mới không thành công");
129                 }
130             }
131             
else
132             {
133                 
int i = 0;
134                 i = Controllers.LoaiThucDonCtrl.UpdateLoaiThucDon(_idLTD, _tenLTD, _dienGiai, _trangThai);
135                 
if (i > 0)
136                 {
137                     MessageBox.Show(
" Sửa thành công");
138                     HienThiDanhSachLTD();
139                     uctLoaiThucDon_Load(sender, e);
140                 }
141                 
else
142                     MessageBox.Show(
"Sửa không thành công");
143             }
144             uctLoaiThucDon_Load(sender, e);
145         }
146
147         
private void btnSua_Click(object sender, EventArgs e)
148         {
149             flag =
1;
150             dis_end(
true);
151             loadcontrol();
152         }
153
154         
private void btnXoa_Click(object sender, EventArgs e)
155         {
156             
string _idLTD = "";
157             
try
158             {
159                 _idLTD = txtIdLTDon.Text;
160             }
161             
catch { }
162             DialogResult dr = MessageBox.Show(
"Bạn có chắc chắn xóa ?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
163             
if (dr == DialogResult.Yes)
164             {
165                 
int i = 0;
166                 i = Controllers.LoaiThucDonCtrl.DeleteLoaiThucDon(_idLTD);
167                 
if (i > 0)
168                 {
169                     MessageBox.Show(
" Xóa thành công");
170                     HienThiDanhSachLTD();
171                     uctLoaiThucDon_Load(sender, e);
172                 }
173                 
else
174                     MessageBox.Show(
"Xóa không thành công");
175             }
176             
else
177                 
return;
178         }
179
180     }
181 }


Gõ tìm kiếm nhanh...